#ifndef DBMANAGER_H
#define DBMANAGER_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVector>
#include <QString>
#include <QObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QThread>
#include <QTimer>
#include <QEventLoop>
#include "config.h"


struct GameData {
    int id;
    QString name;

    GameData(int gameId = 0, const QString& gameName = "") : id(gameId), name(gameName) {}
};


struct GiftData {
    int id;
    QString name;
    int is_txt;

    GiftData(int giftId = 0, const QString& giftName = ""): id(giftId), name(giftName) {}
};


class DBManager : public QObject {
    Q_OBJECT

public:
    DBManager();
    ~DBManager();

    bool createTable(const QString& tableName, const QString& columns);
    bool insertData(const QString& tableName, const QStringList& values);
    QSqlQuery selectData(const QString& tableName, const QString& columns = "*", const QString& condition = "");
    int get_code(const QString data);
    QVector<GameData*> get_games();
    QVector<GiftData> get_gift();
    QVector<GiftData> get_gift(int gameId);
    QString get_gift_by_index(int index);

private:
    QSqlDatabase db;
    QVector<GiftData> m_gift;
};

#endif // DBMANAGER_H
